package com.api.gbhg.huangwm.web;

import com.customization.assets.formmode.sync.SyncAssetsInfoToEcology;
import com.customization.commons.LogTool;
import com.engine.common.util.ParamUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.GCONST;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

@Path("/gb/xmglh")
public class GetXmdmSetBxlc extends BaseBean {
    private LogTool logTool = new LogTool("/log/gbhg/huangwm/web/GetXmdmSetBxlc",false);


    public static void main(String[] args) {
        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");

        RecordSet rs = new RecordSet();
        StringBuffer msg = new StringBuffer();
        msg.append("以下项目存在多个支出渠道： <br />");
        String xmids = "2447457,2447458,2233585";
        rs.execute("SELECT COUNT(id) as c,lcid,(SELECT xmmin FROM dbo.uf_jingfei_version WHERE lcjlsqjlid=uf_jingfeilaiyuan.lcid)AS xmmin FROM dbo.uf_jingfeilaiyuan WHERE lcid IN ("+xmids+") GROUP BY lcid");
        while (rs.next()){
            if(rs.getInt("c")>1){
                msg.append("<a target='_blank' class='child-item wdb' href='/spa/custom/static/index.html#/main/cs/app/6c5adda80aff4ab6929e60d5a626e0f1_YstzDetailPage01?requestId="+rs.getString("lcid")+"'>"+rs.getString("xmmin")+"</a> <br />");
            }
        }
        System.err.println(msg);
    }
    /**
     * 获取员工公务卡
     * @param request
     * @param response
     * @return
     */
    @GET
    @Path("/GetXmglh")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> GetXMglh(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        logTool.writeLog("=====获取报销流程费用信息财政拨款项目对应项目关联号=====");
        Map<String, Object> apiResult = new HashMap<String, Object>();
        Map<String, Object> requestParams = ParamUtil.request2Map(request);
        String uf_gxmdygnkm_id = requestParams.get("uf_gxmdygnkm_id").toString();
        String kmxj = getPropValue("Verification","xj");
        String xmglh = "";
        try {
            RecordSet rs = new RecordSet();
            rs.execute("select * from uf_gxmdygnkm where id="+uf_gxmdygnkm_id);
            rs.next();
            String  hpssjid = rs.getString("hpssjid");//获取核批时数据id,用于判断是否为下级收入
            if(hpssjid.startsWith(kmxj)){
                String xjid = hpssjid.split("_")[1];
                RecordSet rs2 = new RecordSet();
                rs2.execute("select glh from uf_zyczbksr_xj where id="+xjid);
                rs2.next();
                xmglh = rs2.getString("glh");
            }
            apiResult.put("status", true);
            apiResult.put("errorCode", "1");
            apiResult.put("msg", "获取项目关联号成功");
            apiResult.put("xmglh", xmglh);
            return apiResult;
        }catch (Exception e){
            apiResult.put("status", false);
            apiResult.put("errorCode", "-999");
            apiResult.put("msg", "获取项目关联号后台程序异常");
            apiResult.put("xmglh", xmglh);
            e.printStackTrace();
        }
        return apiResult;
    }

    @GET
    @Path("/getRemindInfoFromYsxm")
    @Produces(MediaType.APPLICATION_JSON)
    public Map<String, Object> getRemindInfoFromYsxm(@Context HttpServletRequest request, @Context HttpServletResponse response) {
        logTool.writeLog("=====获取报销流程预算项目是否存在多核批渠道的提示返回流程=====");
        Map<String, Object> apiResult = new HashMap<String, Object>();
        apiResult.put("hasMsg",false);
        Map<String, Object> requestParams = ParamUtil.request2Map(request);
        String xmids = requestParams.get("xmids").toString();
        StringBuffer msg = new StringBuffer();
        try {
            msg.append("以下项目存在多个支出渠道：<br /> ");
            RecordSet rs = new RecordSet();
            rs.execute("SELECT COUNT(id) as c,lcid,(SELECT xmmin FROM dbo.uf_jingfei_version WHERE lcjlsqjlid=uf_jingfeilaiyuan.lcid)AS xmmin FROM dbo.uf_jingfeilaiyuan WHERE lcid IN ("+xmids+") GROUP BY lcid");
            while (rs.next()){
                if(rs.getInt("c")>1){
                    apiResult.put("hasMsg",true);
                    msg.append("<a target='_blank' class='child-item wdb' href=''>"+rs.getString("xmmin")+"</a> <br />");
                }
            }
            apiResult.put("status", true);
            apiResult.put("errorCode", "1");
            apiResult.put("msg", msg.toString());
            return apiResult;
        }catch (Exception e){
            apiResult.put("status", false);
            apiResult.put("errorCode", "-999");
            apiResult.put("msg", "获取项目是否多渠道信息异常");
            e.printStackTrace();
        }
        return apiResult;
    }
}
